package com.b2c.common.advice;

import com.b2c.common.enums.ExceptionEnums;
import com.b2c.common.exception.MrException;
import com.b2c.common.vo.ExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @ClassName CommonExceptionHandier
 * @Description: TODO
 * @Author shenyaqi
 * @Date 2020/7/14
 * @Version V1.0
 **/

//异常公共用
    @ControllerAdvice
public class CommonExceptionHandier {
        @ExceptionHandler(MrException.class)
        public ResponseEntity<ExceptionResult> exceptionHadler(MrException ne){
            ExceptionEnums ex = ne.getExceptionenums();

            System.out.println("异常捕捉到"+ne.getExceptionenums().getMsg());
            return ResponseEntity.status(ex.getCode()).body(new ExceptionResult(ex));
        }
}
